---
title: "Quickstart"
description: "Create your first Codemod package and run it locally."
---

A **Codemod package** is a set of files that define an automated code transformation. Codemod Packages let you create, test, and distribute reusable transformations that update source code across entire codebases.

Packages range from quick, single-file refactors to advanced, multi-step migrations. They're fully portable—run them locally, in CI, or share with your team.

import { PackagesDemo } from "/snippets/packages-demo.mdx";

<Frame>
    <PackagesDemo />
</Frame>

<Steps>
  <Step title="Create a new Codemod package">

    Scaffold a new Codemod package:

    ```bash
    npx codemod init
    ```

    Each package includes your transformation logic (written in JavaScript, TypeScript, or YAML), a project manifest, and [workflow](/cli/packages/building-workflows) specification.

    When creating a new codemod project, you'll be prompted for:

    - **Project directory**
    - **Codemod type:**
      - <Tooltip tip="Best for simple code transformations. Uses the JavaScript ast-grep engine.">JavaScript ast-grep (jssg) codemod</Tooltip>
      - <Tooltip tip="Best for orchestrating large-scale migration campaigns. Combines shell commands, YAML ast-grep rules, and JS codemods into a single workflow.">Multi-step workflow (shell command, YAML & jssg)</Tooltip>
    - **Target language**
    - **Project name**
    - **Description**
    - **Author**
    - **License type**
    - **If your codemod is private**

    This creates a new folder with the required files and structure.
  </Step>

  <Step title="Explore the generated project">
    An example Codemod package:

    ```plaintext
    example-codemod/
    ├── .gitignore
    ├── README.md
    ├── codemod.yaml        #  manifest and metadata
    ├── workflow.yaml       # Workflow definition for running the codemod
    ├── scripts/            # JS/TS codemods and shell scripts
    │   └── codemod.ts      # JS ast-grep codemod entry point
    └── rules/              # YAML ast-grep rule definitions
        └── config.yml
    ```

    <Info>
      You can combine different codemod types in a single package. The <code>scripts/</code> and <code>rules/</code> folders are conventional, not required—use any paths you prefer as long as you reference them correctly from <code>workflow.yaml</code>.
    </Info>

    Check out the [Codemod package structure](/cli/packages/package-structure) for more details.
  </Step>

  <Step title="Understand an example workflow">
    The generated <code>workflow.yaml</code> will differ depending on the codemod type you select:

    ```yaml Combined (jssg + ai + yaml + registry + shell)
    version: "1"
    nodes:
      - id: run-all
        name: Combined Example
        type: automatic
        steps:
          # 1) JS ast-grep (jssg)
          - name: "JS ast-grep codemod"
            js-ast-grep:
              js_file: "scripts/codemod.ts"
              base_path: "."
              language: "typescript"
              include:
                - "**/*.ts"
                - "**/*.tsx"

          # 2) AI step
          - name: "AI review"
            ai:
              prompt: |
                Summarize risky changes and suggest tests.

          # 3) YAML ast-grep
          - name: "Apply YAML ast-grep rules"
            ast-grep:
              config_file: "rules/config.yml"
              base_path: "./src"
              include:
                - "**/*.ts"
              exclude:
                - "**/*.test.ts"

          # 4) Codemod Registry
          - name: "Run registry codemod"
            codemod:
              source: "@scope/package"
              args: ["--flag", "value"]
              env:
                NODE_ENV: production
              working_dir: "."

          # 5) Shell command
          - name: "Format code"
            run: npx prettier --write "**/*.{ts,tsx,js,jsx}"

    ```

    Learn more about building workflows [here](/cli/packages/building-workflows).
  </Step>

  <Step title="Validate & run your Codemod package">
    ```bash
    npx codemod workflow validate -w workflow.yaml
    npx codemod workflow run -w workflow.yaml
    ```

    This will check your workflow for errors and then run it locally.

    <Info>
      The <code>workflow validate</code> command checks syntax and schema compliance, but not logical correctness. Always test with real data to ensure expected behavior.
    </Info>
  </Step>
</Steps>
